//
//  SSToolBarView.swift
//  weibo
//
//  Created by 邵帅 on 16/6/27.
//  Copyright © 2016年 groupNineObject. All rights reserved.
//

import UIKit

class SSToolBarView: UIView {

    var footerViewModel: SSStatusCellModel?{
        
        didSet{
            
            retweetButton.setTitle(footerViewModel?.retweetString, forState: .Normal)
            commentButton.setTitle(footerViewModel?.commentString, forState: UIControlState.Normal)
            goodButton.setTitle(footerViewModel?.goodString, forState: UIControlState.Normal)
            
        }
        
    }
    
    // 第一步 -- 重写构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // 第二步 -- 定义一个方法,来实现 视图的添加和布局
    private func setupUI(){
        
        addSubview(retweetButton)
        addSubview(commentButton)
        addSubview(goodButton)
        
        // 三个按钮的平铺,做重要的是 宽度平铺,需要设置 2个按钮的宽度和另外一个按钮的宽度一致
        retweetButton.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            //            make.right.equalTo(commentButton.snp_left)
            make.bottom.equalTo(self.snp_bottom)
            
            // 设置一个宽度
            make.width.equalTo(commentButton.snp_width)
            
        }
        
        commentButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetButton.snp_right)
            make.top.equalTo(self.snp_top)
            make.right.equalTo(goodButton.snp_left)
            make.bottom.equalTo(self.snp_bottom)
            
            //
        }
        
        goodButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.right.equalTo(self.snp_right)
            make.bottom.equalTo(self.snp_bottom)
            
            // 设置一个宽度
            make.width.equalTo(commentButton.snp_width)
        }
        
    }
    
    // 第三步: 懒加载控件
    
    /// 转发按钮
    private lazy var retweetButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setTitle("转发", forState: UIControlState.Normal)
        
        button.setImage(UIImage(named: "timeline_icon_retweet"), forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        return button
    }()
    
    /// 评论按钮
    private lazy var commentButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setTitle("评论", forState: UIControlState.Normal)
        
        button.setImage(UIImage(named: "timeline_icon_comment"), forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        return button
    }()
    
    ///  点赞
    private lazy var goodButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setTitle("点赞", forState: UIControlState.Normal)
        
        button.setImage(UIImage(named: "timeline_icon_like"), forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        return button
    }()
}
